<?php


namespace App\HttpController;

use App\Service\IndexService;
use EasySwoole\HttpAnnotation\AnnotationTag\Api;
use EasySwoole\HttpAnnotation\AnnotationTag\ApiDescription;
use EasySwoole\HttpAnnotation\AnnotationTag\ApiFail;
use EasySwoole\HttpAnnotation\AnnotationTag\ApiSuccess;
use EasySwoole\HttpAnnotation\AnnotationTag\Param;
use EasySwoole\HttpAnnotation\Utility\AnnotationDoc;

class Index extends BaseController
{
    /**
     * @Api(name="接口文档说明",path="/",version="1.0")
     * @ApiDescription(value="接口文档说明")
     * @Param(name="root", description="http://api.lhzhwy.xyz")
     * @Param(name="authorization", description="登录后所得token")
     * @ApiSuccess({"code": "200", "msg": "成功信息", "result": "成功返回数据"})
     * @ApiFail({"code": "400", "msg" : "失败信息", "result": null})
     * @ApiFail({"code": "403", "msg" : "未登录", "result": null})
     * @ApiFail({"code": "404", "msg" : "接口不存在", "result": null})
     * @ApiFail({"code": "500", "msg" : "服务器错误", "result": null})
     */
    public function index(): bool
    {
        return $this->writeJsonSuccess('success', '接口调用完成');
    }

    /**
     * @Api(name="文档地址",path="/doc",version="1.0")
     * @ApiDescription(value="文档地址")
     */
    public function doc()
    {
        $doc = new AnnotationDoc();
        $doc->setProjectName('龙海智慧物业API接口文档');
        $string = $doc->scan2Html(EASYSWOOLE_ROOT . '/App/HttpController');
        $this->response()->withAddedHeader('Content-type', "text/html;charset=utf-8");
        $this->response()->write($string);
    }

    /**
     * @Api(name="旅游资源",path="/lvy",version="1.0")
     * @ApiDescription(value="旅游资源")
     * @return bool
     */
    public function lvy(){
        $res = IndexService::getInstance()->lvy();
        if (!$res['result']) {
            return $this->writeJsonError($res['msg']);
        }
        return $this->writeJsonSuccess($res['data'], $res['msg']);
    }
}